package com.example.xiaoxueqixiangmu.Adapters;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.xiaoxueqixiangmu.R;
import com.example.xiaoxueqixiangmu.bean.Order;
import com.example.xiaoxueqixiangmu.bean.Train;

import java.util.List;

public class OrderAdapter extends ArrayAdapter<Order> {


        private Context context;
        private List<Order> OrderListdata ;
        public OrderAdapter(@NonNull Context context, int resource, @NonNull List<Order> OrderListdata) {
            super(context, resource,OrderListdata);
            this.context = context;
            this.OrderListdata = OrderListdata;
        }

        @SuppressLint("ResourceType")
        @NonNull
        @Override
        public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
            //1、解析布局
            View layout;
           OrderHolder orderHolder;
            if (convertView==null){
                layout = LayoutInflater.from(context).inflate(R.layout.order_list_item_layout, parent, false);
                orderHolder = new OrderHolder();
                orderHolder.tv_cheming = layout.findViewById(R.id.tv_cheming);
                orderHolder.startTime = layout.findViewById(R.id.tv_checi);
                orderHolder.arriveTime = layout.findViewById(R.id.riqi);
                orderHolder.seatName = layout.findViewById(R.id.dizhi);
                orderHolder.seatNum= layout.findViewById(R.id.zhifuYN);
                orderHolder.imageView1= layout.findViewById(R.id.imageView);//图片
                layout.setTag(orderHolder);
            }else {
                layout = convertView;
                orderHolder = (OrderHolder) layout.getTag();
            }
            //2、实例化控件
			/*ImageView imageView = layout.findViewById(R.id.imageView);
			TextView trainNo = layout.findViewById(R.id.trainNo);*/
            //3、控件赋值、事件监听、可见性
            Order order = getItem(position);
            orderHolder.tv_cheming.setText(order.getId());
            orderHolder.startTime.setText(order.getStatus());
            orderHolder.seatName.setText((CharSequence) order.getTrain());
            orderHolder.imageView1.setImageResource(R.id.imageView1);
            orderHolder.imageView2.setImageResource(R.id.imageView2);
            orderHolder.imageView.setImageResource(R.id.imageView);
            //4、返回布局
            return layout;
        }

        class OrderHolder{
            ImageView imageView,imageView1,imageView2;
            TextView tv_cheming,startTime,arriveTime,seatName,seatNum;
        }
    }



